package com.db.server;

import com.db.server.task.TaskQueue;

import java.io.IOException;
import java.io.ObjectOutput;

/**
 * ResponseSender is used for send messages through socket output.
 */
public class ResponseSender extends Thread {
    private TaskQueue queue;
    private ObjectOutput out;

    public ResponseSender(TaskQueue queue, ObjectOutput out) {
        this.queue = queue;
        this.out = out;

    }

    public void run() {
        try {
            while (true) {
                out.writeObject(queue.remove().doTask());
            }
        } catch (IOException | NullPointerException e) {
        }
    }
}
